﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using TileEngine.tiles;

namespace TileEngine.items
{
    class Defaultitem:Iitem
    {
        #region variables
        public Vector2 location;
        public Vector2 velocity;
        public int height=20;
        public int width=20;
        #endregion
        #region methods
        virtual public void useDraw(SpriteBatch spriteBatch, Color tint)
        {
        }
        virtual public int getStackMax()
        {
            return 1;
        }
        virtual public void mouseLeftClick(GameTime gametime)
        {
        }
        virtual public void mouseRightClick(GameTime gametime)
        {
        }
        virtual public void update(GameTime gameTime)
        {
            if ((Global.currentWorld.player.Location - location).Length() < 10)
            {
                Global.currentWorld.player.inventory.addItem(this);
                Global.currentWorld.items.Remove(this);
                return;
            }
            if((Global.currentWorld.player.Location-location).Length()<60){
                Vector2 newv = (Global.currentWorld.player.Location-location);
                newv.Normalize();
                velocity = newv * 5;
                location += velocity;
                return;
                }

            if (!World.isMovePossible(new Rectangle((int)(location.X + velocity.X), (int)(location.Y), width, height)))
                velocity.X = 0;
            if (World.isMovePossible(new Rectangle((int)(location.X + velocity.X), (int)(location.Y + velocity.Y), width, height)))
            {
                velocity += Global.currentWorld.Gravity - velocity * new Vector2(0.004f, 0.001f);
                location.X += velocity.X * Global.tileSize.X * gameTime.ElapsedGameTime.Milliseconds;
                location.Y += velocity.Y * Global.tileSize.Y * gameTime.ElapsedGameTime.Milliseconds;
            }
            else
                velocity = new Vector2(0f, 0f);

        }
        virtual public string[] getInfo()
        {
            return new string[]{ "No Information","This item has","no Information"};
        }
        virtual public Color getLight()
        {
            return Color.Black;
        }
        virtual public void draw(SpriteBatch spriteBatch,Color tint)
        {
            spriteBatch.Draw(getTexture(), new Rectangle((int)location.X - (int)Camera.Location.X, (int)location.Y - (int)Camera.Location.Y, Global.tileSize.X, Global.tileSize.Y), tint);
        }
        virtual public Texture2D getTexture()
        {
            return null;
        }
        public Vector2 getLocation()
        {

            return location;
        }
        virtual public Type getTile()
        {
            return typeof(Empty);
        }
        #endregion

        public static Vector2 getRandomVelocity(){
            return new Vector2((float)Global.myRandom.NextDouble() * 0.016f - 0.008f, (float)Global.myRandom.NextDouble() * 0.016f - 0.008f);
        }
    }
}
